package com.pllandxzx.controller;

import com.pll.dto.ResponseDto;
import com.pllandxzx.dto.ResponseDTO;
import com.pllandxzx.service.MarketingService;
import com.pllandxzx.vo.AddManageCardVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName MarketingController
 * @Description TODO
 * @Author 小鹿
 * @Date 2025/6/13 9:45
 */

@Tag(name = "MarketingController")
@RestController
@RequestMapping("/marketing")
public class MarketingController
{
    @Autowired
    private MarketingService marketingService;

    @Operation(summary = "获取所有优惠券", description = "可根据活动名称获取所有管理端和商家端发布的优惠券")
    @GetMapping("/getAllMarketingList")
    public ResponseDto getAllMarketingList(
            @RequestParam("activityName") String activityName,
            @RequestParam("page") Integer page,
            @RequestParam("pageSize") Integer pageSize,
            @RequestParam("type")  Integer type){
        return marketingService.getAllMarketingList(activityName,page,pageSize,type);
    }

    @Operation(summary = "新增优惠券", description = "只有管理端可以新增优惠券")
    @PostMapping("/addManageCard")
    public ResponseDto addManageCard(@RequestBody AddManageCardVo addManageCardVo){
        return marketingService.addManageCard(addManageCardVo);
    }

    @Operation(summary = "删除优惠券", description = "根据对应cardId删除优惠券")
    @DeleteMapping("/delete/{id}")
    public ResponseDto delete(@PathVariable("id")Integer cardId){
        return marketingService.delete(cardId);
    }

    @Operation(summary = "修改优惠券属性", description = "可修改优惠券所有属性")
    @PutMapping("/edit/{id}")
    public ResponseDto edit(@PathVariable("id")Integer cardId,@RequestBody AddManageCardVo addManageCardVo){
        return marketingService.edit(cardId,addManageCardVo);
    }

    @Operation(summary = "下架优惠券", description = "可通过修改优惠券的截止时间为当前时间-1小时来下架券包")
    @PutMapping("/offlineCard")
    public ResponseDTO offlineCard(@RequestBody AddManageCardVo addManageCardVo){
        System.out.println(addManageCardVo);
        return marketingService.offlineCard(addManageCardVo);
    }
}